package com.app.tool.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/redis")
public class RedisController {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @GetMapping("/setString")
    public Boolean setString(String key, String value) {
        return redisTemplate.opsForValue().setIfAbsent(key, value, 30, TimeUnit.SECONDS);
    }

    @GetMapping("/getString")
    public String getString(String key) {
        return redisTemplate.opsForValue().get(key);
    }

}
